$('body').css('height',(document.body.clientHeight-90)+'px');
function articledetail(articleid,dataid){
    server.loadindex('page/cms/cmsdetail/cmsdetail','articleid='+articleid+'&dataid='+dataid);
};
var cmsdata={
    page:1,
    totalPage:0,
    limit:15,
    cmsCategoryId:""
};

window.addEventListener('onDropdown', function(event){

    if(!cmsdata.totalPage||cmsdata.page<cmsdata.totalPage){
        cmsdata.page++;
        loadData();
    }
});
function tosearcherpage() {
    // console.log("cmsCategoryId===="+cmsdata.cmsCategoryId);
    server.loadindex('page/cms/seacher/seacher','cmsCategoryId='+cmsdata.cmsCategoryId,true);
}
 function loadData() {
    var cmsCategoryId = server.getQueryString('cmsCategoryId');
     cmsdata.cmsCategoryId = cmsCategoryId;

     // console.log("cms页面获取到ID："+cmsCategoryId);
    if(server.isEmpty(cmsCategoryId)){
        pop_up('无效的分类ID');
        return;
    }
    if(cmsdata.page>1&&cmsdata.page>cmsdata.totalPage){
        pop_up('没有更多了');
        return;
    }
    var searchString = {cmsCategoryId:cmsdata.cmsCategoryId, page:cmsdata.page,limit:cmsdata.limit};
    var cmsKey = server.getQueryString("cmsKey");
    // console.log("cmsKey="+cmsKey);
    if(!server.isEmpty(cmsKey)){
        searchString = {cmsCategoryId:cmsdata.cmsCategoryId, page:cmsdata.page,limit:cmsdata.limit,cmsKey:cmsKey};
    }
    server.req('wechat/cmsarticle/article',searchString,function (e) {
// console.log("list...........");
// console.log(e)
        var strHtml = '<div class="nodata">\n' +
            '            <div class="nodata-image">\n' +
            '                <img src="img/icons/search.png" />\n' +
            '            </div>\n' +
            '            <div class="nodata-text">\n' +
            '                <label>没有找到任何数据</label>\n' +
            '            </div>\n' +
            '        </div>';
        cmsdata.totalPage = (e.totalPage)||0;
        if(e.code==0){

            var data = e.data;
             if(e.size>0) strHtml = "";
                if(cmsdata.page==1)$("#cmslist").html("");
            data.forEach(function (item,index) {
                var title = item.title;
                if(title.length>18){
                    title = title.substring(0,18)+"...";
                }
                strHtml = strHtml+'<div class="cmslist-item" onclick="articledetail('+item.id+','+item.articleDataId+')">\n' +
                    '            <div class="cmslist-item-left">\n' +
                    '                <label>'+title+'</label>\n' +
                    '            </div>\n' +
                    '            <div class="cmslist-item-right">\n' +
                    '                <img src="'+item.image+'" />\n' +
                    '            </div>\n' +
                    '        </div>';
            });
            // console.log(strHtml)
            if(cmsdata.page==1){
                $("#cmslist").html(strHtml);
            }else{
                $("#cmslist").append(strHtml)
            }
           // $("#cmslist").html(strHtml);
        }
    })
};

loadData();